/*========================================================================================================SETTINGS===============================*/ %e 1019 %p 2807 %n 371 %k 284 %a 1213 %o 1117 %{ /*========================================================================================================SETS===================================*/ %} D [0-9] NZ [1-9] H [a-fA-F0-9] HP (0[xX]) M [+-] E ([Ee]{M}?{D}+) P ([Pp]{M}?{D}+) WS [ \t\v\n\f] %{ /*========================================================================================================C=DECLARATIONS=========================*/ %} %{ /*=======================================================================SYSTEM=SETTINGS===============*/ /*#include "y.tab.h"*/ /* For compilation using C */ #include "semantic.h" /* For compilation using C++ */ extern void yyerror(const char *); /* prints grammar violation message */ extern int sym_type(const char *); /* returns type from symbol table */ /*=======================================================================LEX=YACC=SETTINGS=============*/ extern YYSTYPE yylval; #define YYSTYPE char* /*=======================================================================PROGRAM=SETINGS===============*/ #include #include #define READ_STORE \ { \ yylval.str = strdup (yytext); \ printf ("%s", yytext); \ } %} %{ /*=======================================================================================================================================================================================================*/ /*=======================================================================================================================================================================================================*/ /*=======================================================================================================================================================================================================*/ %} %% %{ /*==============================================================================================KEY=WORDS==============================*/ %} "sin" { READ_STORE; return(SIN); } "cos" { READ_STORE; return (COS); } "tg" { READ_STORE; return (TG); } "arcsin" { READ_STORE; return (ARCSIN); } "arccos" { READ_STORE; return (ARCCOS); } "arctg" { READ_STORE; return (ARCTG); } "sh" { READ_STORE; return (SH); } "ch" { READ_STORE; return (CH); } "cth" { READ_STORE; return (CTH); } "exp" { READ_STORE; return (EXP); } "ln" { READ_STORE; return (LN); } "log" { READ_STORE; return (LOG); } "round" { READ_STORE; return (ROUND); } "max" { READ_STORE; return (MAX); } "min" { READ_STORE; return (MIN); } "rand" { READ_STORE; return (RAND); } "abs" { READ_STORE; return (ABS); } ("pi"|"PI"|"Pi"|"pI") { READ_STORE; return (PI); } ("e"|"E") { READ_STORE; return (E); } "(" { READ_STORE; return '('; } ")" { READ_STORE; return ')'; } "-" { READ_STORE; return '-'; } "+" { READ_STORE; return '+'; } "*" { READ_STORE; return '*'; } "/" { READ_STORE; return '/'; } "%" { READ_STORE; return '%'; } "^" { READ_STORE; return '^'; } "," { READ_STORE; return ','; } %{ /*==============================================================================================CONSTANTS==============================*/ %} ({HP}{H}+) { READ_STORE; return CONSTANT; } ({NZ}{D}*) { READ_STORE; return CONSTANT; } ({D}+) { READ_STORE; return CONSTANT; } ({D}+{E}) { READ_STORE; return CONSTANT; } ({D}*"."{D}+{E}?) { READ_STORE; return CONSTANT; } ({D}+"."{E}?) { READ_STORE; return CONSTANT; } ({HP}{H}+{P}) { READ_STORE; return CONSTANT; } ({HP}{H}*"."{H}+{P}) { READ_STORE; return CONSTANT; } ({HP}{H}+"."{P}) { READ_STORE; return CONSTANT; } %{ /*==============================================================================================WHITE=SPACES===========================*/ %} {WS} { printf ("%s", yytext); /* whitespace separates tokens */ } %{ /*==============================================================================================DISCARS=BAD=CARACTERS==================*/ %} . { printf ("\"%s\" /*Bad character - skipped*/", yytext); /* discard bad characters */ } %%/*=====================================================================================================================================================================================================*/ /*=======================================================================================================================================================================================================*/ /*=======================================================================================================================================================================================================*/ /*=======================================================================LEX=YACC=FUNCTIONS============*/ /*========================================================YYWRAP================*/ int yywrap(void) /* called at end of input */ { return 1; /* terminate now */ } /*=======================================================================PROGRAM=FUNCTIONS=============*/